package com.tansun.bums.controller;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/test")
public class ExampleController {

    @Value("${spring.application.name}")
    String applicationName;

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public ResponseEntity hello() {
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("applicationName", applicationName);
        jsonObject.put("RequestMapping", "/test/hello");
        jsonObject.put("ResponseDate", format);

        log.info(jsonObject.toJSONString());
        return ResponseEntity.ok(jsonObject);
    }


}
